package synchronicity.host;

import synchronicity.calendar.Calendar;
import synchronicity.discovery.MockDiscovery;

/**
 * For unit testing 
 */
public class MockSchedulerHostFactory implements SchedulerHostFactory {
	private static MockSchedulerHostFactory instance;
	
	private volatile static int hostNumber = 0;

	private MockSchedulerHostFactory() {
	}

	public static synchronized MockSchedulerHostFactory getInstance() {
		if (instance == null)
			instance = new MockSchedulerHostFactory();
		return instance;
	}

	public SchedulerHost createSchedulerHost(Calendar factory) {
		SchedulerHostImpl result = new SchedulerHostImpl(factory, MockDiscovery
				.getInstance());
		result.setHostIdentifier("host"+hostNumber);
		hostNumber++;
		MockDiscovery.getInstance().addHost(result);
		return result;
	}
}
